package com.phunware.swipeToDismiss.pager;

import android.view.View;
import android.view.ViewGroup;

import com.phunware.swipeToDismiss.interfaces.ViewBinder;

public class SwipingPagerAdapter<T> extends BasePagerAdapter {
	private final ViewBinder<T> mBinder;
	private T mItem;
	private View convertView;

	public SwipingPagerAdapter(ViewBinder<T> binder, T item) {
		mBinder = binder;
		mItem = item;
	}

	public SwipingPagerAdapter(ViewBinder<T> binder) {
		mBinder = binder;
	}

	public void setItem(T item) {
		mItem = item;
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return 3;
	}

	@Override
	public Object instantiateItem(View parent, int position) {

		if (1 == position) {
			getMainView(parent);
			((ViewGroup) parent).addView(convertView);
			return convertView;
		}
		return null;
	}

	// allows direct access to the child view
	public View getMainView(View parent) {
		convertView = mBinder.bind(mItem, convertView, (ViewGroup) parent);
		return convertView;
	}

}
